import AbstractRuntimeView from "../../../common/abstract/mvc/AbstractRuntimeView";
import { soundMgr } from "../../../common/def/sound";
import Event from "../../../common/manager/EventClick";
import MyTools from "../../../common/util/MyTools";
import { ADMgr } from "../../../common/wxComponent/ADManager";
/**
 * 
 * @author: xj.huang
 * @date: 2021/08/13 18:51:27
 */
export default class EndBXView  extends AbstractRuntimeView<null,null>{
    private startBtn: Laya.Image;
    private progressBar: Laya.ProgressBar;
    private trea_box;
    /**随机数 */
    private ranProNum: number;
    /**是否强制 */
    private isforce: boolean;
    private currClickNum = 0;
    private downTime = 100
    private isCanClick = true;
    
    constructor() {
        super()
    }
    onOnce() {
        this.trea_box = this.gameConfig.ad_move_conf.page.trea_box;
        this.ranProNum = MyTools.getRandomNumInt(this.trea_box.min, this.trea_box.max);
        this.progressBar.value = 0;
        console.log("界面出来了EndBoxView")
        Laya.timer.loop(1000, this, this.SubPro);
        this.onAddEvent()
    }
    onEnable(){
        super.onEnable()
        this.startBtn.visible = true;
        ADMgr.closeAllBanner()
    }
    private onAddEvent() {
        Event.onClick(this.startBtn, this, this.onCrazyClick)
        // ZYEventMgr.on(ADEvent.)
    }
    private onCrazyClick() {
        if (!this.isCanClick) return
        this.onSetProBar = (this.currClickNum) / 100;
        if (this.currClickNum >= this.ranProNum) {
            this.downTime = 100
            this.isCanClick = false;
            Laya.timer.clear(this, this.SubPro);
            this.onSetProBar=1;
            ADMgr.showBanner(1000000000000000000000)
            this.startBtn.visible = false;
            Laya.timer.once(5000,this,this.onCloseView)
        } else {
            this.currClickNum += this.trea_box.addPro
        }
        soundMgr.playClickSound()
    }
    private set onSetProBar(v) {
        Laya.Tween.to(this.progressBar, { value: v }, 100)
    }
    private SubPro() {
        if (this.progressBar.value <= 0) return
        let v = this.progressBar.value - (this.trea_box.subPro) / 200
        Laya.Tween.to(this.progressBar, { value: v }, 100, null, Laya.Handler.create(this, () => {
            if (this.progressBar.value <= 0) this.progressBar.value = 0
        }))
    }
    private onCloseView(){
        console.log("关闭")
        this.isCanClick = true;
        this.currClickNum = 0
        this.onClose("手动关闭");
        ADMgr.showBanner(0.2)
    }
}